this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};this.BX.Landing.UI=this.BX.Landing.UI||{};(function(e,t,n,r,i,o,a,s,c,l,u,d,g,m,h,f,p){"use strict";var v,y,C;function b(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function I(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?b(Object(n),!0).forEach((function(t){babelHelpers.defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):b(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function O(e,t){F(e,t);t.add(e)}function B(e,t,n){F(e,t);t.set(e,n)}function F(e,t){if(t.has(e)){throw new TypeError("Cannot initialize the same private elements twice on an object")}}function k(e,t,n){if(!t.has(e)){throw new TypeError("attempted to get private field on non-instance")}return n}var P="crm_webform";var T=new WeakMap;var E=new WeakSet;var L=new WeakSet;var D=function(e){babelHelpers.inherits(h,e);babelHelpers.createClass(h,null,[{key:"getInstance",value:function e(){var t=n.PageObject.getRootWindow();var r=t.BX.Landing.UI.Panel.FormSettingsPanel;if(!r.instance&&!h.instance){r.instance=new h}return r.instance||h.instance}}]);function h(){var e;babelHelpers.classCallCheck(this,h);e=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(h).call(this));O(babelHelpers.assertThisInitialized(e),L);O(babelHelpers.assertThisInitialized(e),E);babelHelpers.defineProperty(babelHelpers.assertThisInitialized(e),"adjustActionsPanels",false);B(babelHelpers.assertThisInitialized(e),T,{writable:true,value:"PHONE_NOT_VERIFIED"});e.setEventNamespace("BX.Landing.UI.Panel.FormSettingsPanel");e.setTitle(r.Loc.getMessage("LANDING_FORM_SETTINGS_PANEL_TITLE"));e.lsCache=new i.Cache.LocalStorageCache;i.Dom.addClass(e.layout,"landing-ui-panel-form-settings");e.subscribe("onCancel",(function(){BX.onCustomEvent(babelHelpers.assertThisInitialized(e),"BX.Landing.Block:onFormSettingsClose",[e.getCurrentBlock().id])}));e.disableOverlay();if(e.isCrmFormPage()){var n=l.Env.getInstance().getOptions().formEditorData.dictionary;var o=n.sidebarButtons.map((function(e){return new m.SidebarButton(I(I({},e),{},{child:true}))}));e.setSidebarButtons(o);var a=n.scenarios.map((function(e){return new t.Preset(e)}));e.setPresets(a);var s=n.scenarioCategories.map((function(e){return new t.PresetCategory(e)}));e.setCategories(s)}else{i.Dom.append(e.getBlockSettingsButton().render(),e.getRightHeaderControls())}e.subscribe("onCancel",e.onCancelClick.bind(babelHelpers.assertThisInitialized(e)));i.Dom.append(e.getExpertSwitcherLayout(),e.layout);return e}babelHelpers.createClass(h,[{key:"getExpertSwitcherLayout",value:function e(){var t=this;return this.cache.remember("switcherLayout",(function(){var e=function e(){t.getExpertModeSwitcher().node.click()};return i.Tag.render(v||(v=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="landing-ui-expert-switcher">\n\t\t\t\t\t','\n\t\t\t\t\t<span onclick="','" class="landing-ui-expert-switcher-label">\n\t\t\t\t\t\t',"\n\t\t\t\t\t</span>\n\t\t\t\t</div>\n\t\t\t"])),t.getExpertModeSwitcher().node,e,r.Loc.getMessage("LANDING_FORM_EXPERT_MODE_SWITCHER_LABEL"))}))}},{key:"getExpertModeSwitcher",value:function e(){var t=this;return this.cache.remember("expertModeSwitcher",(function(){var e=n.PageObject.getRootWindow();var r=new e.BX.UI.Switcher({checked:t.isExpertModeEnabled()});i.Dom.addClass(r.node,"ui-switcher-size-sm ui-switcher-color-green");i.Event.bind(r.node,"click",t.onExpertSwitcherClick.bind(t));return r}))}},{key:"onExpertSwitcherClick",value:function e(){this.lsCache.set("formEditorExpertMode",this.getExpertModeSwitcher().isChecked());this.onExpertModeChange()}},{key:"getCurrentPreset",value:function e(){var t=this.getFormOptions(),n=t.templateId;var r=this.getPresets().find((function(e){return e.options.id===n}));if(r){return r}return this.getPresets().find((function(e){return e.options.id==="expert"}))}},{key:"onExpertModeChange",value:function e(){var t=this;var n=this.getCurrentPreset();if(this.getExpertModeSwitcher().isChecked()&&i.Type.isArrayFilled(n.options.expertModeItems)){this.clearSidebar();this.getSidebarButtons().filter((function(e){return n.options.expertModeItems.includes(e.id)})).forEach((function(e){if(!n.options.items.includes(e.id)){e.deactivate()}t.appendSidebarButton(e)}))}else{var r=this.getSidebarButtons().find((function(e){return e.isActive()}));var o=this.getSidebarButtons().filter((function(e){return n.options.items.includes(e.id)}));this.clearSidebar();o.forEach((function(e){t.appendSidebarButton(e)}));if(r&&!n.options.items.includes(r.id)){var a=function(){if(i.Type.isStringFilled(n.options.defaultSection)){return n.options.defaultSection}return"fields"}();var s=this.getSidebarButtons().find((function(e){return e.id===a}));if(s){s.getLayout().click()}}}}},{key:"isExpertModeEnabled",value:function e(){return this.lsCache.get("formEditorExpertMode",false)}},{key:"isCrmFormPage",value:function e(){return l.Env.getInstance().getOptions().specialType==="crm_forms"}},{key:"getFormDesignButton",value:function e(){var t=this;return this.cache.remember("formDesignButton",(function(){return new c.Button({text:r.Loc.getMessage("LANDING_FORM_DESIGN_BUTTON"),color:c.Button.Color.LIGHT_BORDER,round:true,className:"landing-ui-panel-top-button",onclick:t.onFormDesignButtonClick.bind(t)})}))}},{key:"getBlockSettingsButton",value:function e(){var t=this;return this.cache.remember("blockSettingsButton",(function(){return new c.Button({text:r.Loc.getMessage("LANDING_FORM_SETTINGS_BLOCK_SETTINGS_BUTTON_TEXT"),color:c.Button.Color.LIGHT_BORDER,round:true,className:"landing-ui-panel-top-button",onclick:t.onBlockSettingsButtonClick.bind(t)})}))}},{key:"onBlockSettingsButtonClick",value:function e(){var t=this;if(this.getCurrentBlock()){this.hide().then((function(){t.getCurrentBlock().showContentPanel()}))}}},{key:"onFormDesignButtonClick",value:function e(){if(this.getCurrentBlock()){this.getCurrentBlock().onFormDesignClick()}}},{key:"getLoader",value:function e(){var t=this;return this.cache.remember("loader",(function(){return new a.Loader({target:t.body})}))}},{key:"showLoader",value:function e(){i.Dom.addClass(this.layout,"landing-ui-panel-state-content-load");void this.getLoader().show();i.Dom.hide(this.sidebar);i.Dom.hide(this.content);i.Dom.hide(this.getExpertSwitcherLayout())}},{key:"hideLoader",value:function e(){i.Dom.removeClass(this.layout,"landing-ui-panel-state-content-load");this.getLoader().hide();i.Dom.show(this.sidebar);i.Dom.show(this.content);if(i.Type.isArrayFilled(this.getCurrentPreset().options.expertModeItems)){i.Dom.show(this.getExpertSwitcherLayout())}}},{key:"showContentLoader",value:function e(){i.Dom.addClass(this.layout,"landing-ui-panel-state-body-load");babelHelpers.get(babelHelpers.getPrototypeOf(h.prototype),"showContentLoader",this).call(this)}},{key:"hideContentLoader",value:function e(){i.Dom.removeClass(this.layout,"landing-ui-panel-state-body-load");babelHelpers.get(babelHelpers.getPrototypeOf(h.prototype),"hideContentLoader",this).call(this)}},{key:"load",value:function e(){var n=this;var r=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};if(r.showWithOptions){var a=l.Env.getInstance().getOptions().formEditorData;var c=a.dictionary;var u=c.sidebarButtons.map((function(e){return new m.SidebarButton(I(I({},e),{},{child:true}))}));this.setSidebarButtons(u);var d=c.scenarios.map((function(e){return new t.Preset(e)}));this.setPresets(d);var g=c.scenarioCategories.map((function(e){return new t.PresetCategory(e)}));this.setCategories(g);this.setCrmFields(a.crmFields);this.setCrmCompanies(a.crmCompanies);this.setCrmCategories(a.crmCategories);this.setAgreements(a.agreements);var h=i.Runtime.clone(a.formOptions);if(h.agreements.use!==true){h.agreements.use=true;h.data.agreements=[]}this.setFormOptions(h);this.setFormDictionary(a.dictionary);return Promise.resolve()}var f=o.Backend.getInstance().batch("Form::getCrmFields",{crmFields:{action:"Form::getCrmFields",data:null},crmCompanies:{action:"Form::getCrmCompanies",data:null},crmCategories:{action:"Form::getCrmCategories",data:null},agreements:{action:"Form::getAgreements",data:null}}).then((function(e){n.setCrmFields(e.crmFields.result);n.setCrmCompanies(e.crmCompanies.result);n.setCrmCategories(e.crmCategories.result);n.setAgreements(e.agreements.result)}));var p=s.FormClient.getInstance().getOptions(this.getCurrentFormId()).then((function(e){var t=i.Runtime.clone(e);if(t.agreements.use!==true){t.agreements.use=true;t.data.agreements=[]}n.setFormOptions(t)}));var v=s.FormClient.getInstance().getDictionary().then((function(e){n.setFormDictionary(e);var r=e.sidebarButtons.map((function(e){return new m.SidebarButton(I(I({},e),{},{child:true}))}));n.setSidebarButtons(r);var i=e.scenarios.map((function(e){return new t.Preset(e)}));n.setPresets(i);var o=e.scenarioCategories.map((function(e){return new t.PresetCategory(e)}));n.setCategories(o)}));return Promise.all([f,p,v])}},{key:"setAgreements",value:function e(t){this.cache.set("agreements",i.Runtime.orderBy(t,["id"],["asc"]))}},{key:"getAgreements",value:function e(){return this.cache.get("agreements")}},{key:"isLeadEnabled",value:function e(){return this.getFormDictionary().document.lead.enabled}},{key:"setCurrentBlock",value:function e(t){this.cache.set("currentBlock",t)}},{key:"getCurrentBlock",value:function e(){return this.cache.get("currentBlock")}},{key:"getSaveOriginalFileNameAlert",value:function e(){return this.cache.remember("saveOriginalFileNameAlert",(function(){var e=new g.Alert({text:r.Loc.getMessage("LANDING_CRM_FORM_MAIN_OPTION_WARNING"),color:g.AlertColor.WARNING});return e.render()}))}},{key:"show",value:function e(){var t=this;var r=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{formOptions:{}};if(!this.layout.parentNode){this.enableToggleMode()}if(!this.isFormCreated()){this.disableTransparentMode()}var o=l.Env.getInstance().getOptions(),a=o.mainOptions;if(a.saveOriginalFileName===false){this.prependContent(this.getSaveOriginalFileNameAlert());var s=i.Text.toNumber(i.Dom.style(this.closeButton.getLayout(),"top"));var c=this.getSaveOriginalFileNameAlert().getBoundingClientRect().height;i.Dom.style(this.closeButton.getLayout(),"top","".concat(s+c,"px"))}this.setCurrentBlock(r.block);this.setCurrentFormId(r.formId);this.setCurrentFormInstanceId(r.instanceId);this.showLoader();this.load(r).then((function(){t.hideLoader();var e=t.getFormOptions();if(i.Type.isPlainObject(r.formOptions)){var n=i.Runtime.merge(t.getFormOptions(),r.formOptions);t.setFormOptions(n)}if(r.state==="presets"){var o=t.getPresetIdFromRequest();var a=false;if(o){a=t.getPresets().find((function(e){return e.options.id===o}))}if(a){t.applyPreset(a)}else{t.onPresetFieldClick();t.activatePreset(e.templateId)}}else{var s=t.getPresets().find((function(t){return t.options.id===e.templateId}));if(!s){s=t.getPresets().find((function(e){return e.options.id==="expert"}))}if(t.isFormCreated()){t.applyPreset(s);t.onPresetFieldClick()}else{t.applyPreset(s,true)}}t.setInitialFormOptions(i.Runtime.clone(t.getFormOptions()));if(!t.isFormCreated()){t.onExpertModeChange()}}))["catch"]((function(e){if(i.Type.isArrayFilled(e)){var n=510;var r=e.some((function(e){return String(e.code)===String(n)}));if(r){t.getLoader().hide();i.Dom.show(t.sidebar);i.Dom.show(t.content);i.Dom.hide(t.footer);i.Dom.append(t.getAccessError(),t.content)}}console.error(e)}));var d=n.PageObject.getEditorWindow();i.Dom.addClass(d.document.body,"landing-ui-hide-action-panels-form");void u.StylePanel.getInstance().hide();this.disableHistory();return babelHelpers.get(babelHelpers.getPrototypeOf(h.prototype),"show",this).call(this,r).then((function(){setTimeout((function(){var e=t.getCurrentBlock().node.offsetTop;n.PageObject.getEditorWindow().scrollTo(0,e)}),300);BX.onCustomEvent(t,"BX.Landing.Block:onFormSettingsOpen",[t.getCurrentBlock().id]);return Promise.resolve(true)}))}},{key:"getHistoryHint",value:function e(){return this.cache.remember("historyHint",(function(){var e=i.Tag.render(y||(y=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<span \n\t\t\t\t\tclass="landing-ui-history-hint"\n\t\t\t\t\tdata-hint="','"\n\t\t\t\t\tdata-hint-no-icon\n\t\t\t\t></span>\n\t\t\t'])),i.Text.encode(r.Loc.getMessage("LANDING_FORM_HISTORY_DISABLED_HINT")));var t=n.PageObject.getRootWindow();t.BX.UI.Hint.initNode(e);return e}))}},{key:"disableHistory",value:function e(){var t=n.PageObject.getRootWindow();var r=t.BX.Landing.UI.Panel.Top;if(r){var o=r.getInstance(),a=o.undoButton,s=o.redoButton;i.Dom.addClass(a,"landing-ui-disabled-from-form");i.Dom.addClass(s,"landing-ui-disabled-from-form");i.Dom.append(this.getHistoryHint(),a.parentElement)}}},{key:"enableHistory",value:function e(){var t=n.PageObject.getRootWindow();var r=t.BX.Landing.UI.Panel.Top;if(r){var o=r.getInstance(),a=o.undoButton,s=o.redoButton;i.Dom.removeClass(a,"landing-ui-disabled-from-form");i.Dom.removeClass(s,"landing-ui-disabled-from-form");i.Dom.remove(this.getHistoryHint())}}},{key:"getAccessError",value:function e(){return this.cache.remember("accessErrorMessage",(function(){return i.Tag.render(C||(C=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t<div class="landing-ui-access-error-message">\n\t\t\t\t\t<div class="landing-ui-access-error-message-text">\n\t\t\t\t\t\t',"\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t"])),r.Loc.getMessage("LANDING_CRM_ACCESS_ERROR_MESSAGE"))}))}},{key:"getPresetIdFromRequest",value:function e(){var t=new i.Uri(window.top.location.href);return t.getQueryParam("preset")}},{key:"isFormCreated",value:function e(){var t=n.PageObject.getRootWindow();var r=new i.Uri(t.location.href);return i.Text.toBoolean(r.getQueryParam("formCreated"))}},{key:"setCurrentFormId",value:function e(t){this.cache.set("currentFormId",i.Text.toNumber(t))}},{key:"getCurrentFormId",value:function e(){return this.cache.get("currentFormId")}},{key:"setCurrentFormInstanceId",value:function e(t){this.cache.set("currentFormInstanceId",t)}},{key:"getCurrentFormInstanceId",value:function e(){return this.cache.get("currentFormInstanceId")}},{key:"setCrmFields",value:function e(t){this.cache.set("fields",t)}},{key:"getCrmFields",value:function e(){return this.cache.get("fields")||{}}},{key:"setCrmCompanies",value:function e(t){this.cache.set("companies",t)}},{key:"getCrmCompanies",value:function e(){return this.cache.get("companies")||[]}},{key:"setCrmCategories",value:function e(t){this.cache.set("crmCategories",t)}},{key:"getCrmCategories",value:function e(){return this.cache.get("crmCategories")||[]}},{key:"setFormOptions",value:function e(t){this.cache.set("formOptions",t)}},{key:"getFormOptions",value:function e(){return i.Runtime.clone(this.cache.get("formOptions")||{})}},{key:"setFormDictionary",value:function e(t){this.cache.set("formDictionary",t)}},{key:"getFormDictionary",value:function e(){return this.cache.get("formDictionary")||{}}},{key:"setInitialFormOptions",value:function e(t){this.cache.set("initialFormOptions",i.Runtime.clone(t))}},{key:"getInitialFormOptions",value:function e(){return this.cache.get("initialFormOptions")}},{key:"getCrmForm",value:function e(){var t=this;var n=i.Reflection.getClass("b24form.App");if(n){if(this.getCurrentFormInstanceId()){return n.get(this.getCurrentFormInstanceId())}var r=-1;var o=babelHelpers.toConsumableArray(this.getCurrentBlock().node.parentElement.childNodes).reduce((function(e,n){if(i.Dom.attr(n,"data-subtype")==="form"){r+=1;if(n===t.getCurrentBlock().node){return r}}return e}),0);return n.list()[o]}return null}},{key:"onChange",value:function e(t){var n=this;var r=t.getData();var o=t.getTarget().getValue();Promise.resolve(o).then((function(e){if(r.skipPrepare){var t=n.getFormOptions();if(Reflect.has(e,"presetFields")||Reflect.has(e,"document")||Reflect.has(e,"result")){var o={};if(Reflect.has(e,"document")){o.payment=e.document.payment;delete e.document.payment}return I(I(I({},t),e),o)}if(Reflect.has(e,"embedding")||Reflect.has(e,"callback")||Reflect.has(e,"whatsapp")||Reflect.has(e,"name")&&Reflect.has(e,"data")&&Reflect.has(e.data,"useSign")){var a=i.Runtime.merge(t,e);if(Reflect.has(e,"responsible")){a.responsible.users=e.responsible.users}return a}if(Reflect.has(e,"recaptcha")){var c=e.recaptcha,l=c.key,u=c.secret;delete e.recaptcha.key;delete e.recaptcha.secret;var d={};if(!i.Type.isNil(l)){d.key=l}if(!i.Type.isNil(u)){d.secret=u}return I(I({},t),{},{captcha:I(I({},t.captcha),d),data:I(I({},t.data),e)})}return I(I({},t),{},{data:I(I({},t.data),e)})}return s.FormClient.getInstance().prepareOptions(n.getFormOptions(),e).then((function(t){if(e.agreements){t.data=i.Runtime.merge(t.data,e)}if(e.integration){t.integration=e.integration}if(e.fields){t.data.fields=t.data.fields.map((function(t,n){return i.Runtime.merge(t,e.fields[n])}))}return t}))})).then((function(e){BX.Landing.UI.Panel.Top.getInstance().setFormName(e.name);n.setFormOptions(e);n.getCrmForm().adjust(i.Runtime.clone(e.data))}))}},{key:"getPersonalizationVariables",value:function e(){var t=this;return this.cache.remember("personalizationVariables",(function(){return t.getFormDictionary().personalization.list.map((function(e){return{name:e.name,value:e.id}}))}))}},{key:"getDefaultValuesVariables",value:function e(){var t=this;return this.cache.remember("personalizationVariables",(function(){var e=t.getFormDictionary(),n=e.properties;if(i.Type.isPlainObject(n)&&i.Type.isArrayFilled(n.list)){return n.list.map((function(e){return{name:e.name,value:e.id}}))}return[]}))}},{key:"getContent",value:function e(t){var r=this;var o=this.getSidebarButtons().find((function(e){return t===e.options.id}));var a=o.options.data.extension;var s=this.cache.remember(a,(function(){var e=n.PageObject.getRootWindow();return e.BX.Runtime.loadExtension(a).then((function(e){return e["default"]}))}));return s.then((function(e){if(i.Type.isFunction(e)){return new e({formOptions:r.getFormOptions(),dictionary:r.getFormDictionary(),crmFields:r.getCrmFields(),companies:r.getCrmCompanies(),categories:r.getCrmCategories(),agreements:r.getAgreements(),isLeadEnabled:r.isLeadEnabled(),form:r.getCrmForm()})}return null}))}},{key:"onPresetClick",value:function e(t){if(t.getTarget().options.openable){this.disableTransparentMode()}var n=new i.Uri(window.top.location.toString());n.removeQueryParam("formCreated");n.removeQueryParam("preset");window.top.history.replaceState(null,document.title,n.toString());this.applyPreset(t.getTarget())}},{key:"getCheckActionConfirm",value:function e(){return this.cache.remember("checkActionConfirm",(function(){var e=n.PageObject.getRootWindow();return new e.BX.UI.Dialogs.MessageBox({buttons:d.MessageBoxButtons.OK_CANCEL})}))}},{key:"applyPreset",value:function e(t){var r=this;var a=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;var c=this.getPresets().find((function(e){return i.Dom.hasClass(e.getLayout(),"landing-ui-panel-preset-active")}));this.getPresets().forEach((function(e){e.deactivate()}));if(!a){var l=function(){if(i.Type.isArrayFilled(t.options.actions)){return Promise.all(t.options.actions.map((function(e){if(e.id==="showTour"){var i=n.PageObject.getRootWindow();var o=new i.BX.UI.Tour.Guide({onEvents:false,steps:e.data.steps});o.start()}if(e.id==="showHelp"){if(window.top.BX.Helper){window.top.BX.Helper.show(e.data.href)}}if(e.id==="check"){return s.FormClient.getInstance().check({templateId:t.options.id}).then((function(e){if(e.success===false){var t=r.getCheckActionConfirm();t.setTitle(e.message.title);t.setMessage(e.message.description);t.setOkCaption(e.message.confirmButton);t.setCancelCaption(e.message.cancelButton);return new Promise((function(e){t.setOkCallback((function(){t.getOkButton().setDisabled(false);t.getCancelButton().setDisabled(false);t.close();e(true)}));t.setCancelCallback((function(){t.getOkButton().setDisabled(false);t.getCancelButton().setDisabled(false);t.close();e(false)}));t.show()}))}return Promise.resolve(true)}))}return Promise.resolve()})))}return Promise.resolve()}();if(t.options.openable){this.showLoader();void l.then((function(e){var n=function(){if(i.Type.isArrayFilled(t.options.actions)){return t.options.actions.reduce((function(t,n,r){return I(I({},t),{},babelHelpers.defineProperty({},n.id,e[r]))}),{})}return{}}();if(Reflect.has(n,"check")&&n.check===true||!Reflect.has(n,"check")){r.getPresets().forEach((function(e){e.deactivate()}));t.activate();s.FormClient.getInstance().prepareOptions(r.getFormOptions(),{templateId:t.options.id}).then((function(e){return o.Backend.getInstance().action("Form::getCrmFields").then((function(t){r.setCrmFields(t);f.FieldsPanel.getInstance().setCrmFields(t);return e}))})).then((function(e){BX.Landing.UI.Panel.Top.getInstance().setFormName(e.name);r.setFormOptions(I(I({},e),{},{templateId:t.options.id}));r.getCrmForm().adjust(i.Runtime.clone(e.data));if(r.isFormCreated()){r.onPresetFieldClick();r.activatePreset(t.options.id)}else{babelHelpers.get(babelHelpers.getPrototypeOf(h.prototype),"applyPreset",r).call(r,t);if(i.Type.isArrayFilled(t.options.expertModeItems)){i.Dom.show(r.getExpertSwitcherLayout());r.onExpertModeChange()}else{i.Dom.hide(r.getExpertSwitcherLayout())}}r.hideLoader()}))}else{r.hideLoader();r.enableTransparentMode();if(c){c.activate();t.deactivate()}}}))}}else{if(t.options.openable){babelHelpers.get(babelHelpers.getPrototypeOf(h.prototype),"applyPreset",this).call(this,t);if(i.Type.isArrayFilled(t.options.expertModeItems)){i.Dom.show(this.getExpertSwitcherLayout());this.onExpertModeChange()}else{i.Dom.hide(this.getExpertSwitcherLayout())}this.hideLoader()}t.activate()}}},{key:"getFormNode",value:function e(){var t=this;return this.cache.remember("formNode",(function(){return t.getCurrentBlock().node.querySelector("[data-b24form-use-style]")}))}},{key:"useBlockDesign",value:function e(){var t=this;return this.cache.remember("useBlockDesign",(function(){return i.Text.toBoolean(i.Dom.attr(t.getFormNode(),"data-b24form-use-style"))}))}},{key:"getCurrentCrmEntityName",value:function e(){var t=this.getFormOptions().document.scheme;var n=this.getFormDictionary().document.schemes.find((function(e){return String(t)===String(e.id)}));return n.name}},{key:"getNotSynchronizedFields",value:function e(){return s.FormClient.getInstance().checkFields(this.getFormOptions()).then((function(e){return e}))}},{key:"showSynchronizationPopup",value:function e(t){var n=this;return new Promise((function(e){var o=function t(n){n.close();e(true)};var a=function t(n){n.close();e(false)};var s=function(){var e=r.Loc.getMessage("LANDING_SYNCHRONIZATION_POPUP_ENTITY_TEMPLATE").replace("{entityName}",i.Text.encode(n.getCurrentCrmEntityName()));return r.Loc.getMessage("LANDING_SYNCHRONIZATION_POPUP_DESCRIPTION").replace("{entityName}",i.Text.encode(e))}();var c=function(){var e=babelHelpers.toConsumableArray(t).map((function(e){return r.Loc.getMessage("LANDING_SYNCHRONIZATION_POPUP_FIELD_TEMPLATE").replace("{fieldName}",i.Text.encode(e))}));if(t.length>1){var n=e.pop();return r.Loc.getMessage("LANDING_SYNCHRONIZATION_POPUP_TEXT").replace("{fieldsList}",e.join(", ")).replace("{lastField}",n)}return r.Loc.getMessage("LANDING_SYNCHRONIZATION_POPUP_TEXT_1").replace("{field}",e.join(", "))}();window.top.BX.UI.Dialogs.MessageBox.confirm("".concat(s,"<br><br>").concat(c),r.Loc.getMessage("LANDING_SYNCHRONIZATION_POPUP_TITLE"),o,r.Loc.getMessage("LANDING_SYNCHRONIZATION_POPUP_OK_BUTTON_LABEL"),a)}))}},{key:"showSynchronizationErrorPopup",value:function e(t){var n=t.reduce((function(e,t){return"".concat(e,"\n\n").concat(t)}),"");window.top.BX.UI.Dialogs.MessageBox.alert(n)}},{key:"getErrorAlert",value:function e(){return this.cache.remember("errorAlert",(function(){var e=n.PageObject.getRootWindow();return new e.BX.UI.Dialogs.MessageBox({title:r.Loc.getMessage("LANDING_FORM_SAVE_ERROR_ALERT_TITLE"),buttons:d.MessageBoxButtons.OK,popupOptions:{maxHeight:310}})}))}},{key:"onSaveClick",value:function e(){var t=this;var a=this.getFormDictionary();BX.onCustomEvent(this,"BX.Landing.Block:onFormSave",[this.getCurrentBlock().id]);if(i.Type.isPlainObject(a.permissions)&&i.Type.isPlainObject(a.permissions.form)&&a.permissions.form.edit===false){var c=n.PageObject.getRootWindow();c.BX.UI.Dialogs.MessageBox.alert(r.Loc.getMessage("LANDING_FORM_SAVE_PERMISSION_DENIED"));return}i.Dom.addClass(this.getSaveButton().layout,"ui-btn-wait");this.getNotSynchronizedFields().then((function(e){if(i.Type.isPlainObject(e.sync)){if(i.Type.isArrayFilled(e.sync.errors)){t.showSynchronizationErrorPopup(e.sync.errors);return false}if(i.Type.isArrayFilled(e.sync.fields)){var n=e.sync.fields.map((function(e){return e.label}));return t.showSynchronizationPopup(n)}}return true})).then((function(e){if(e){var a=new i.Uri(window.top.location.toString());a.removeQueryParam("formCreated");window.top.history.replaceState(null,document.title,a.toString());var c=t.getInitialFormOptions();var l=t.getFormOptions();var u=function(){if(!t.isCrmFormPage()){var e=i.Runtime.clone(l);e.data.design=i.Runtime.clone(c.data.design);return e}return l}();if(u.data.recaptcha.use&&!t.getFormDictionary().captcha.hasKeys&&!u.captcha.hasDefaults){u.data.recaptcha.use=false;var g=n.PageObject.getRootWindow();var m=new g.BX.UI.Dialogs.MessageBox({title:r.Loc.getMessage("LANDING_FORM_SAVE_CAPTCHA_ALERT_TITLE"),message:r.Loc.getMessage("LANDING_FORM_SAVE_CAPTCHA_ALERT_TEXT_2"),buttons:d.MessageBoxButtons.OK,onOk:function e(){m.close();i.Dom.removeClass(t.getSaveButton().layout,"ui-btn-wait")}});m.show()}void s.FormClient.getInstance().saveOptions(u).then((function(e){BX.onCustomEvent(t,"BX.Landing.Block:onAfterFormSave",[t.getCurrentBlock().id]);t.setFormOptions(e);t.setInitialFormOptions(e);s.FormClient.getInstance().resetCache(e.id);i.Dom.removeClass(t.getSaveButton().layout,"ui-btn-wait");var n=t.getSidebarButtons().find((function(e){return e.isActive()}));return o.Backend.getInstance().action("Form::getCrmFields").then((function(r){t.setCrmFields(r);f.FieldsPanel.getInstance().setCrmFields(r);if(n&&!i.Dom.hasClass(t.layout,"landing-ui-panel-mode-transparent")){n.getLayout().click()}return e}));if(t.isCrmFormPage()){i.Dom.addClass(t.getSaveButton().layout,"ui-btn-icon-done");var a=t.getSaveButton().layout.innerText;t.getSaveButton().setText(r.Loc.getMessage("LANDING_FORM_EDITOR_SAVE_BUTTON_STATE_SAVED"));setTimeout((function(){i.Dom.removeClass(t.getSaveButton().layout,"ui-btn-icon-done");t.getSaveButton().setText(a)}),1500)}else{void t.hide()}}))["catch"]((function(e){if(i.Type.isArrayFilled(e)){if(k(t,E,N).call(t,e)){k(t,L,w).call(t)}else{var o=e.map((function(e){return i.Text.encode(e.message)})).join("<br><br>");var a=t.getErrorAlert();a.setMessage(o);a.show()}}else{var s=n.PageObject.getRootWindow();s.BX.UI.Dialogs.MessageBox.alert(r.Loc.getMessage("LANDING_FORM_SAVE_UNKNOWN_ERROR_ALERT_TEXT"),r.Loc.getMessage("LANDING_FORM_SAVE_ERROR_ALERT_TITLE"))}i.Dom.removeClass(t.getSaveButton().layout,"ui-btn-wait")}));if(t.useBlockDesign()&&t.isCrmFormPage()){t.disableUseBlockDesign()}}else{i.Dom.removeClass(t.getSaveButton().layout,"ui-btn-wait")}}))}},{key:"isChanged",value:function e(){return JSON.stringify(this.getFormOptions())!==JSON.stringify(this.getInitialFormOptions())}},{key:"disableUseBlockDesign",value:function e(){i.Dom.attr(this.getFormNode(),"data-b24form-use-style","N");this.cache.set("useBlockDesign",false);o.Backend.getInstance().action("Landing\\Block::updateNodes",{block:this.getCurrentBlock().id,data:{".bitrix24forms":{attrs:{"data-b24form-use-style":"N"}}},lid:this.getCurrentBlock().lid,siteId:this.getCurrentBlock().siteId},{code:this.getCurrentBlock().manifest.code})}},{key:"onCancelClick",value:function e(){var t=this.getInitialFormOptions();this.getCrmForm().adjust(t.data);BX.Landing.UI.Panel.Top.getInstance().setFormName(t.name);void this.hide()}},{key:"hide",value:function e(){var t=n.PageObject.getEditorWindow();i.Dom.removeClass(t.document.body,"landing-ui-hide-action-panels-form");this.enableHistory();return babelHelpers.get(babelHelpers.getPrototypeOf(h.prototype),"hide",this).call(this)}},{key:"onSidebarButtonClick",value:function e(t){var n=t.getTarget();if(n.options.id==="design"){this.onFormDesignButtonClick()}else{babelHelpers.get(babelHelpers.getPrototypeOf(h.prototype),"onSidebarButtonClick",this).call(this,t)}}}],[{key:"sanitize",value:function e(t){if(i.Type.isStringFilled(t)){return i.Text.decode(t).replace(/<style[^>]*>.*<\/style>/gm,"").replace(/<script[^>]*>.*<\/script>/gm,"").replace(/<[^>]+>/gm,"")}return t}}]);return h}(t.BasePresetPanel);function N(e){var t=this;return e.some((function(e){return e.code===babelHelpers.classPrivateFieldGet(t,T)}))}function w(){if(typeof p.PhoneVerify!=="undefined"){p.PhoneVerify.getInstance().setEntityType(P).setEntityId(this.getCurrentFormId()).startVerify({sliderTitle:r.Loc.getMessage("LANDING_FORM_EDITOR_PHONE_VERIFY_CUSTOM_SLIDER_TITLE"),title:r.Loc.getMessage("LANDING_FORM_EDITOR_PHONE_VERIFY_CUSTOM_TITLE"),description:r.Loc.getMessage("LANDING_FORM_EDITOR_PHONE_VERIFY_CUSTOM_DESCRIPTION")})}}e.FormSettingsPanel=D})(this.BX.Landing.UI.Panel=this.BX.Landing.UI.Panel||{},BX.Landing.UI.Panel,BX.Landing,BX.Landing,BX,BX.Landing,BX,BX.Crm.Form,BX.UI,BX.Landing,BX.Landing.UI.Panel,BX.UI.Dialogs,BX.UI,BX.Landing.UI.Button,BX.UI.Tour,BX.Landing.UI.Panel,BX.Bitrix24);
//# sourceMappingURL=formsettingspanel.bundle.map.js